package com.wdd.atcrowdfunding.manager.service.impl;

import com.wdd.atcrowdfunding.bean.RolePermission;
import com.wdd.atcrowdfunding.manager.dao.RolePermissionMapper;
import com.wdd.atcrowdfunding.manager.service.RolePermissionService;
import com.wdd.atcrowdfunding.vo.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RolePermissionServiceImpl implements RolePermissionService {
    @Autowired
    private RolePermissionMapper rolePermissionMapper;

    @Override
    public List<Integer> queryPermissionidsByRoleid(Integer roleid) {
        return rolePermissionMapper.queryPermissionidsByRoleid(roleid);
    }

    @Override
    public int saveRolePermissionRelationship(Integer roleid, Data datas) {
        rolePermissionMapper.deleteRolePermissionRelationship(roleid);
        int totalCount = 0;
        List<Integer> ids = datas.getIds();
        for(Integer permissionid :ids){
            RolePermission rolePermission = new RolePermission();
            rolePermission.setRoleid(roleid);
            rolePermission.setPermissionid(permissionid);
            int count = rolePermissionMapper.insert(rolePermission);
            totalCount +=count;
        }
        return totalCount;
    }
}
